package com.mangguo.tingjian.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mangguo.tingjian.content.dto.*;
import com.mangguo.tingjian.content.mapper.*;
import com.mangguo.tingjian.content.service.IContentDataService;
import com.mangguo.tingjian.sound.entity.Album;
import com.mangguo.tingjian.sound.entity.AlbumPeriod;
import com.mangguo.tingjian.sound.mapper.AlbumPeriodMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;

@Service
@AllArgsConstructor
@Slf4j
public class ContentDataServiceImpl implements IContentDataService {

    private final DwPlayerMapper dwPlayerMapper;

    private final DwClickMapper dwClickMapper;

    private final DwAudioMapper dwAudioMapper;

    private final DwUserCommentMapper dwUserCommentMapper;

    private final DwUserFavoritesMapper dwUserFavoritesMapper;

    private final UserSubscriptionMapper userSubscriptionMapper;

    private final DwUserAttentionanchorMapper dwUserAttentionanchorMapper;


    private final com.mangguo.tingjian.sound.mapper.AlbumMapper albumMapper;

    private final AlbumPeriodMapper albumPeriodMapper;

    private final ExecutorService executorService = new ThreadPoolExecutor(5, 10,

            30L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());


    @Override
    public ContentDataAudioResult getSimpleForAudio(Long audioId, Integer start, Integer end) {
        ContentDataAudioResult result = new ContentDataAudioResult();

        Long count = dwPlayerMapper.countAudioPlayBetweenDate(start, end, audioId);
        Long sumContentSec = dwPlayerMapper.sumAudioContentSecBetweenDate(start, end, audioId);
        Long sumPlaySec = dwPlayerMapper.sumAudioPlaySecBetweenDate(start, end, audioId);
        result.setPlayCount(dwPlayerMapper.countAudioPlayBetweenDate(start, end, audioId));
        if(sumPlaySec != null && sumContentSec!= null && sumContentSec != 0){
            result.setPlayAvg(sumPlaySec.doubleValue() / sumContentSec.doubleValue());
        }
        if(sumPlaySec != null && count!= null && count != 0){
            result.setListenSec(sumPlaySec.doubleValue() / count.doubleValue());
        }

        result.setListenMostTimeInt(dwPlayerMapper.getAudioPlayTopHourBetweenDate(start, end, audioId));
        result.setFavoritesCount(dwUserFavoritesMapper.countFavoritesByContentIdBetweenDate(start, end, audioId, 2));
        result.setCommentCount(dwUserCommentMapper.countCommentByContentIdBetweenDate(start, end, audioId, 2));
        result.setShareCount(dwClickMapper.countShareByContentIdBetweenDate(start, end, audioId, 2));

        return result;
    }

    @Override
    public ContentDataAlbumResult getSimpleForAlbum(List<Long> audioIds, Long albumId, Integer start, Integer end) {
        ContentDataAlbumResult result = new ContentDataAlbumResult();

        Long count = dwPlayerMapper.countAlbumPlayBetweenDate(start, end, audioIds);
        Long sumContentSec = dwPlayerMapper.sumAlbumContentSecBetweenDate(start, end, audioIds);
        Long sumPlaySec = dwPlayerMapper.sumAlbumPlaySecBetweenDate(start, end, audioIds);
        result.setPlayCount(dwPlayerMapper.countAlbumPlayBetweenDate(start, end, audioIds));
        if(sumPlaySec != null && sumContentSec!= null && sumContentSec != 0){
            result.setPlayAvg(sumPlaySec.doubleValue() / sumContentSec.doubleValue());
        }
        if(sumPlaySec != null && count!= null && count != 0){
            result.setListenSec(sumPlaySec.doubleValue() / count.doubleValue());
        }
        result.setListenMostTimeInt(dwPlayerMapper.getAlbumPlayTopHourBetweenDate(start, end, audioIds));
        result.setSubscription(userSubscriptionMapper.countSubscriptionBetweenDate(start, end, albumId, 1));
        return result;
    }

    @Override
    public ContentDataAuthorResult getSimpleForAuthor(String authorName, Integer start, Integer end) {
        ContentDataAuthorResult result = new ContentDataAuthorResult();

        Long sumContentSec = dwPlayerMapper.sumAuthorContentSecBetweenDate(start, end, authorName);
        Long sumPlaySec = dwPlayerMapper.sumAuthorPlaySecBetweenDate(start, end, authorName);
        result.setPlayCount(dwPlayerMapper.countAuthorPlayBetweenDate(start, end, authorName));
        if(sumPlaySec != null && sumContentSec!= null && sumContentSec != 0){
            result.setPlayAvg(sumPlaySec.doubleValue() / sumContentSec.doubleValue());
        }

        result.setListenMostTimeInt(dwPlayerMapper.getAuthorPlayTopHourBetweenDate(start, end, authorName));
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");
        Integer monthStart = Integer.valueOf(simpleDateFormat.format(new Date())) * 100;
        result.setPlayCountThisMonth(dwPlayerMapper.countAuthorPlayBetweenDate(monthStart, monthStart + 31, authorName));

        result.setFanCount(dwUserAttentionanchorMapper.countAuthorAttentionBetweenDate(start, end, dwAudioMapper.getAuthorIdByAuthorName(authorName)));
        return result;
    }

    @Override
    public List<ContentDataAudioTableResult> getTableDataForAudio(Long audioId, String audioName, Integer start, Integer end) {
        Map<Integer, ContentDataAudioTableResult> map = new ConcurrentHashMap<>();
        List<Integer> dateList = new LinkedList<>();
        try {
            dateList = getBetweenDates(start, end);
        } catch (ParseException e) {
            log.error("获取时间区段异常", e);
        }
        String albumName = dwAudioMapper.getAlbumNameByAudioId(audioId);
        dateList.forEach(dateInt -> {
            ContentDataAudioTableResult contentDataAudioTableResult = new ContentDataAudioTableResult();
            contentDataAudioTableResult.setDate(dateInt);
            contentDataAudioTableResult.setAudio(audioName);
            contentDataAudioTableResult.setAlbum(albumName);
            map.put(dateInt, contentDataAudioTableResult);
        });
        CountDownLatch countDownLatch = new CountDownLatch(5);

        executorService.execute(() ->{
            dwPlayerMapper.getContentDateAudioTableResult(start, end, audioId).forEach(e -> {
                ContentDataAudioTableResult contentDataAudioTableResult =  map.get(e.getDate());
                //app播放量
                contentDataAudioTableResult.setAppPlayCount(e.getAppPlayCount());
                //h5播放量
                contentDataAudioTableResult.setH5PlayCount(e.getH5PlayCount());
                //总播放量
                contentDataAudioTableResult.setAllPlayCount(e.getAllPlayCount());
                //app收听人数
                contentDataAudioTableResult.setAppPeopleCount(e.getAppPeopleCount());
                //h5收听人数
                contentDataAudioTableResult.setH5PeopleCount(e.getH5PeopleCount());
                //总收听人数
                contentDataAudioTableResult.setAllPeopleCount(e.getAllPeopleCount());
                //播放率
                contentDataAudioTableResult.setPlayAvg(e.getPlayAvg());
            });
            countDownLatch.countDown();
        });
        executorService.execute(() ->{
            //总点击量
            dwClickMapper.countAudioClickTime(start, end, audioId).forEach(e -> {
                map.get(e.getMDate()).setAllClickCount(e.getCount());
            });
            countDownLatch.countDown();
        });
        executorService.execute(() ->{
            //点赞数
            dwUserFavoritesMapper.countFavoritesByContentIdBetweenDateGroupByDate(start, end, audioId, 2).forEach(e -> {
                map.get(e.getMDate()).setLikeCount(e.getCount());
            });
            countDownLatch.countDown();
        });
        executorService.execute(() ->{
            //分享数
            dwUserCommentMapper.countCommentByContentIdBetweenDateGroupByDate(start, end, audioId, 2).forEach(e -> {
                map.get(e.getMDate()).setCommentCount(e.getCount());
            });
            countDownLatch.countDown();
        });
        executorService.execute(() ->{
            //评论数
            dwClickMapper.countShareByContentIdBetweenDateGroupByDate(start, end, audioId, 2).forEach(e -> {
                map.get(e.getMDate()).setShareCount(e.getCount());
            });

            countDownLatch.countDown();
        });

//        //app播放量
//        dwPlayerMapper.countAudioPlayTimeByDictCode(start, end, audioId, "600000000000").forEach(e -> {
//            map.get(e.getMDate()).setAppPlayCount(e.getCount());
//        });

//        //h5播放量
//        dwPlayerMapper.countAudioPlayTimeByDictCode(start, end, audioId, "600000000002").forEach(e -> {
//            map.get(e.getMDate()).setH5PlayCount(e.getCount());
//        });

        //总播放量
//        dwPlayerMapper.countAudioPlayTime(start, end, audioId).forEach(e -> {
//            map.get(e.getMDate()).setAllPlayCount(e.getCount());
//        });

//        //app收听人数
//        dwPlayerMapper.countImeiAudioPlayTimeByDictCode(start, end, audioId, "600000000000").forEach(e -> {
//            map.get(e.getMDate()).setAppPeopleCount(e.getCount());
//        });

//        //h5收听人数
//        dwPlayerMapper.countImeiAudioPlayTimeByDictCode(start, end, audioId, "600000000002").forEach(e -> {
//            map.get(e.getMDate()).setH5PeopleCount(e.getCount());
//        });

        //总收听人数
//        dwPlayerMapper.countAudioPeoplePlayTime(start, end, audioId).forEach(e -> {
//            map.get(e.getMDate()).setAllPeopleCount(e.getCount());
//        });

//        map.forEach((mdate, result) -> {

//            Long sumContentSec = dwPlayerMapper.sumAudioContentSecBetweenDate(mdate, mdate, audioId);
////            Long sumPlaySec = dwPlayerMapper.sumAudioPlaySecBetweenDate(mdate, mdate, audioId);
////            if (sumContentSec != null && sumPlaySec != null){
////                //播放率
////                result.setPlayAvg(sumPlaySec.doubleValue() / sumContentSec.doubleValue());
////            }
//            //点赞数
//            result.setLikeCount(dwUserFavoritesMapper.countFavoritesByContentIdBetweenDate(mdate, mdate, audioId, 2));
//            //分享数
//            result.setCommentCount(dwUserCommentMapper.countCommentByContentIdBetweenDate(mdate, mdate, audioId, 2));
//            //评论数
//            result.setShareCount(dwClickMapper.countShareByContentIdBetweenDate(mdate, mdate, audioId, 2));

//        });
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            log.error("多线程获取数据异常", e);
        }
        List<ContentDataAudioTableResult> resultList = new LinkedList<>();
        dateList.forEach(dateInt -> resultList.add(map.get(dateInt)));
        return resultList;
    }

    @Override
    public List<ContentDataAudioTableResult> getTableDataForAudios(List<Long> audioIds, Integer start, Integer end) {
        Map<Integer, Map<Long,ContentDataAudioTableResult>> map = new ConcurrentHashMap<>();
        List<Integer> dateList = new LinkedList<>();
        try {
            dateList = getBetweenDates(start, end);
        } catch (ParseException e) {
            log.error("获取时间区段异常", e);
        }

        Map<Long, String> audioNameMap = new ConcurrentHashMap<>();
        Map<Long, String> albumNameMap = new ConcurrentHashMap<>();
        dwAudioMapper.getAudioNamesByAudioIds(audioIds).forEach(nameResult ->{
            if (nameResult.getAlbumName() != null){
                albumNameMap.put(nameResult.getAudioId(),nameResult.getAlbumName());
            }
            if (nameResult.getAudioName() != null){
                audioNameMap.put(nameResult.getAudioId(),nameResult.getAudioName());
            }

        });

        dateList.forEach(dateInt -> {
            audioIds.forEach(audioId -> {
                ContentDataAudioTableResult contentDataAudioTableResult = new ContentDataAudioTableResult();
                contentDataAudioTableResult.setDate(dateInt);
                contentDataAudioTableResult.setAudioId(audioId);
                contentDataAudioTableResult.setAudio(audioNameMap.get(audioId));
                contentDataAudioTableResult.setAlbum(albumNameMap.get(audioId));

                if(map.get(dateInt) == null){
                    map.put(dateInt, new ConcurrentHashMap<>());
                }
                map.get(dateInt).put(audioId, contentDataAudioTableResult);
            });
        });

        CountDownLatch countDownLatch = new CountDownLatch(5);

        executorService.execute(() ->{
            dwPlayerMapper.getContentDateAudioTableResults(start, end, audioIds).forEach(e -> {
                ContentDataAudioTableResult contentDataAudioTableResult =  map.get(e.getDate()).get(e.getAudioId());
                //app播放量
                contentDataAudioTableResult.setAppPlayCount(e.getAppPlayCount());
                //h5播放量
                contentDataAudioTableResult.setH5PlayCount(e.getH5PlayCount());
                //总播放量
                contentDataAudioTableResult.setAllPlayCount(e.getAllPlayCount());
                //app收听人数
                contentDataAudioTableResult.setAppPeopleCount(e.getAppPeopleCount());
                //h5收听人数
                contentDataAudioTableResult.setH5PeopleCount(e.getH5PeopleCount());
                //总收听人数
                contentDataAudioTableResult.setAllPeopleCount(e.getAllPeopleCount());
                //播放率
                contentDataAudioTableResult.setPlayAvg(e.getPlayAvg());
            });
            countDownLatch.countDown();
        });
        executorService.execute(() ->{
            //总点击量
            dwClickMapper.countAudioClickTimeByContents(start, end, audioIds).forEach(e -> {
                map.get(e.getMDate()).get(e.getContentId()).setAllClickCount(e.getCount());
            });
            countDownLatch.countDown();
        });
        executorService.execute(() ->{
            //点赞数
            dwUserFavoritesMapper.countFavoritesByContentIdBetweenDateGroupByDates(start, end, audioIds, 2).forEach(e -> {
                map.get(e.getMDate()).get(e.getContentId()).setLikeCount(e.getCount());
            });
            countDownLatch.countDown();
        });
        executorService.execute(() ->{
            //分享数
            dwUserCommentMapper.countCommentByContentIdBetweenDateGroupByDates(start, end, audioIds, 2).forEach(e -> {
                map.get(e.getMDate()).get(e.getContentId()).setCommentCount(e.getCount());
            });
            countDownLatch.countDown();
        });
        executorService.execute(() ->{
            //评论数
            dwClickMapper.countShareByContentIdBetweenDateGroupByDates(start, end, audioIds, 2).forEach(e -> {
                map.get(e.getMDate()).get(e.getContentId()).setShareCount(e.getCount());
            });

            countDownLatch.countDown();
        });
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            log.error("多线程获取数据异常", e);
        }
        List<ContentDataAudioTableResult> resultList = new LinkedList<>();
        dateList.forEach(dateInt -> audioIds.forEach(audioId -> resultList.add(map.get(dateInt).get(audioId))));

        return resultList;
    }


    @Override
    public Long getAudioIdByAudioNameAndAlbumName(String audioName, String albumName) {
        return dwAudioMapper.getAudioIdByAudioNameAndAlbumName(audioName, albumName);
    }

    @Override
    public List<Long> getAudioIdByAlbumNameAndCmo(String albumName, String cmo) {
        return dwAudioMapper.getAudioIdByAlbumNameAndCmo(albumName, cmo);
    }

    @Override
    public List<Long> getAudioIdByAlbumId(Long albumId) {
        return dwAudioMapper.getAudioIdByAlbumId(albumId);
    }

    @Override
    public List<Long> getAlbumIdByAuthorName(String authorName) {
        return dwAudioMapper.getAlbumIdByAuthorName(authorName);
    }

    @Override
    public Long getAlbumIdByAlbumNameAndCmo(String albumName, String cmo) {
        return dwAudioMapper.getAlbumIdByAlbumNameAndCmo(albumName, cmo);
    }

    @Override
    public String getAudioNameByAudioId(Long audioId) {
        return dwAudioMapper.getAudioNameByAudioId(audioId);
    }

    @Override
    public List<ContentDataAuthorTableResult> getTableDataForAlbum(Long albumId, Integer start, Integer end) {
        Map<Integer, ContentDataAuthorTableResult> map = new HashMap<>();
        List<Integer> dateList = new LinkedList<>();
        try {
            dateList = getBetweenDates(start, end);
        } catch (ParseException e) {
            log.error("获取时间区段异常", e);
        }
        String albumName = dwAudioMapper.getAlbumNameByAlbumId(albumId);
        dateList.forEach(dateInt -> {
            ContentDataAuthorTableResult contentDataAuthorTableResult = new ContentDataAuthorTableResult();
            contentDataAuthorTableResult.setDate(dateInt);
            contentDataAuthorTableResult.setAlbum(albumName);
            map.put(dateInt, contentDataAuthorTableResult);
        });


        //app播放量
        dwPlayerMapper.countAblumPlayTimeByDictCode(start, end, albumId, "600000000000").forEach(e -> {
            map.get(e.getMDate()).setAppPlayCount(e.getCount());
        });

        //h5播放量
        dwPlayerMapper.countAblumPlayTimeByDictCode(start, end, albumId, "600000000002").forEach(e -> {
            map.get(e.getMDate()).setAppPlayCount(e.getCount());
        });

        //总播放量
        dwPlayerMapper.countAblumPlayTime(start, end, albumId).forEach(e -> {
            map.get(e.getMDate()).setAllPlayCount(e.getCount());
        });

        //app收听人数
        dwPlayerMapper.countImeiAlbumPlayTimeByDictCode(start, end, albumId, "600000000000").forEach(e -> {
            map.get(e.getMDate()).setAppPeopleCount(e.getCount());
        });

        //h5收听人数
        dwPlayerMapper.countImeiAlbumPlayTimeByDictCode(start, end, albumId, "600000000002").forEach(e -> {
            map.get(e.getMDate()).setH5PeopleCount(e.getCount());
        });

        //总收听人数
        dwPlayerMapper.countAlbumPeoplePlayTime(start, end, albumId).forEach(e -> {
            map.get(e.getMDate()).setAllPeopleCount(e.getCount());
        });

        //订阅数
        userSubscriptionMapper.countSubscriptionByAlbumIdBetweenDate(start, end, albumId).forEach(e -> {
            map.get(e.getMDate()).setSubscription(e.getCount());
        });

        map.forEach((mdate, result) -> {
            Long sumContentSec = dwPlayerMapper.sumAlbumContentSecBetweenDateById(mdate, mdate, albumId);
            Long sumPlaySec = dwPlayerMapper.sumAlbumPlaySecBetweenDateById(mdate, mdate, albumId);
            if (sumContentSec != null && sumPlaySec != null){
                //播放率
                result.setPlayAvg(sumPlaySec.doubleValue() / sumContentSec.doubleValue());
            }
        });

        List<ContentDataAuthorTableResult> resultList = new LinkedList<>();
        dateList.forEach(dateInt -> {
            resultList.add(map.get(dateInt));

        });

        return resultList;
    }

    @Override
    public List<ContentDataAuthorTableResult> getTableDataForAlbums(List<Long> albumIds, Integer start, Integer end) {
        Map<Integer, Map<Long,ContentDataAuthorTableResult>> map = new ConcurrentHashMap<>();
        Map<Long,String> albumNameMap = new ConcurrentHashMap<>();
        List<Integer> dateList = new LinkedList<>();
        try {
            dateList = getBetweenDates(start, end);
        } catch (ParseException e) {
            log.error("获取时间区段异常", e);
        }

        List<Long> albumIdsActive = new ArrayList<>();
        //判断albumId是否有效
        albumMapper.selectList(new QueryWrapper<Album>().lambda()
                .in(Album::getId, albumIds)).forEach(album -> {
                    if (album.getRemoveTag().equals(0)){
                        albumNameMap.put(album.getId(),album.getName());
                        albumIdsActive.add(album.getId());
                    }
        });

        dateList.forEach(dateInt -> {
            albumIdsActive.forEach(albumId -> {
                ContentDataAuthorTableResult contentDataAuthorTableResult = new ContentDataAuthorTableResult();
                contentDataAuthorTableResult.setDate(dateInt);
                contentDataAuthorTableResult.setAlbum(albumNameMap.get(albumId));
                if (map.get(dateInt) == null){
                    map.put(dateInt, new ConcurrentHashMap<>());
                }
                map.get(dateInt).put(albumId, contentDataAuthorTableResult);
            });
        });


        CountDownLatch countDownLatch = new CountDownLatch(3);


        executorService.execute(() ->{
            dwPlayerMapper.getContentDateAlbumTableResults(start, end, albumIdsActive).forEach(e -> {
                ContentDataAuthorTableResult contentDataAuthorTableResult =  map.get(e.getDate()).get(e.getAlbumId());
                //app播放量
                contentDataAuthorTableResult.setAppPlayCount(e.getAppPlayCount());
                //h5播放量
                contentDataAuthorTableResult.setH5PlayCount(e.getH5PlayCount());
                //总播放量
                contentDataAuthorTableResult.setAllPlayCount(e.getAllPlayCount());
                //app收听人数
                contentDataAuthorTableResult.setAppPeopleCount(e.getAppPeopleCount());
                //h5收听人数
                contentDataAuthorTableResult.setH5PeopleCount(e.getH5PeopleCount());
                //总收听人数
                contentDataAuthorTableResult.setAllPeopleCount(e.getAllPeopleCount());
                //播放率
                contentDataAuthorTableResult.setPlayAvg(e.getPlayAvg());
            });
            countDownLatch.countDown();
        });

        executorService.execute(() ->{
            //订阅数
            //获取分期id
            Map<Long, Set<Long>> albumToPeriodMap = new ConcurrentHashMap<>();
            Set<Long> allPeriodId = new TreeSet<>();
            albumPeriodMapper.selectList(new QueryWrapper<AlbumPeriod>().lambda().select(AlbumPeriod::getAlbumId,AlbumPeriod::getPeriodId,AlbumPeriod::getRemoveTag)
                    .in(AlbumPeriod::getAlbumId, albumIdsActive)).forEach(albumPeriod -> {
                if (albumPeriod.getRemoveTag() != null && albumPeriod.getRemoveTag().equals(0)){
                    albumToPeriodMap.computeIfAbsent(albumPeriod.getAlbumId(), k -> new TreeSet<>());
                    albumToPeriodMap.get(albumPeriod.getAlbumId()).add(albumPeriod.getPeriodId());
                    allPeriodId.add(albumPeriod.getPeriodId());
                }
            });
            List<Long> allPeriodIdList = new ArrayList<>();
            allPeriodIdList.addAll(allPeriodId);

            //统计分期id订阅数
            Map<Integer,Map<Long, Long>> periodCountMap = new ConcurrentHashMap<>();
            userSubscriptionMapper.countSubscriptionByAlbumIdBetweenDates(start, end, allPeriodIdList, 5).forEach(e -> {
                periodCountMap.putIfAbsent(e.getMDate(), new HashMap<>());
                periodCountMap.get(e.getMDate()).put(e.getContentId(), e.getCount());
            });

            //统计总订阅数
            userSubscriptionMapper.countSubscriptionByAlbumIdBetweenDates(start, end, albumIdsActive, 1).forEach(e -> {
                Long albumId = e.getContentId();
                AtomicReference<Long> count = new AtomicReference<>(0L);
                albumToPeriodMap.get(albumId).forEach(periodId -> count.updateAndGet(v -> v + periodCountMap.get(e.getMDate()).get(periodId)));
                map.get(e.getMDate()).get(e.getContentId()).setSubscription(e.getCount() + count.get());
            });
            countDownLatch.countDown();
        });

        executorService.execute(() ->{
            //总点击量
            dwClickMapper.countAlbumClickTimeByContents(start, end, albumIdsActive).forEach(e -> {
                map.get(e.getMDate()).get(e.getContentId()).setAllClickCount(e.getCount());
            });
            countDownLatch.countDown();
        });

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            log.error("多线程获取数据异常", e);
        }
        List<ContentDataAuthorTableResult> resultList = new LinkedList<>();
        dateList.forEach(dateInt -> {
            albumIdsActive.forEach(albumId -> {

                resultList.add(map.get(dateInt).get(albumId));
            });
        });

        return resultList;
    }

    private List<Integer> getBetweenDates(Integer startInt, Integer endInt) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        Date start = simpleDateFormat.parse(startInt.toString());
        Date end = simpleDateFormat.parse(endInt.toString());
        List<Integer> result = new LinkedList<>();
        Calendar tempStart = Calendar.getInstance();
        tempStart.setTime(start);
//        tempStart.add(Calendar.DAY_OF_YEAR, 1);

        Calendar tempEnd = Calendar.getInstance();
        tempEnd.setTime(end);
        tempEnd.add(Calendar.DAY_OF_YEAR, 1);
        while (tempStart.before(tempEnd)) {
            result.add(Integer.valueOf(simpleDateFormat.format(tempStart.getTime())));
            tempStart.add(Calendar.DAY_OF_YEAR, 1);
        }
        return result;
    }

}
